home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Procedures to handle TNC queueing *)
- (* *)
- (* Copyright 1988, 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- (*===========================================================================*)
- (* TNC_DATA_QUEUED *)
- (* Returns true if data in queue. Will also pop the oldest element off *)
- (* queue and put it in the buffer. *)
- (*===========================================================================*)
-
- FUNCTION tnc_data_queued : BOOLEAN;
-
- VAR
- b : BOOLEAN;
- i : WORD;
- last_chain : str_m_chain;
- look_chain : str_m_chain;
-
- BEGIN;
-
- WITH active_tcb^, active_tcb^.tnc_data DO
- BEGIN;
-
- {$IFDEF DEBUG}
- WRITELN('chain check! -- ', channel, ' -- ', tnc_cmd_data);
- {$ENDIF}
-
- (*-------------------------------------------------------------------*)
- (* Get ready to chase down the chain *)
- (*-------------------------------------------------------------------*)
-
- look_chain := tnc_in_chn;
- b := FALSE;
-
- REPEAT
-
- {$IFDEF DEBUG}
- WITH look_chain^ DO
- WRITELN(str_m_chan, ' -- ', str_m_type);
- {$ENDIF}
-
- {$IFDEF POINT_CHK}
- test_pointer(look_chain);
- {$ENDIF}
-
- (*-----------------------------------------------------------------*)
- (* See if we have a match on what's wanted and what we have *)
- (*-----------------------------------------------------------------*)
-
- WITH look_chain^ DO
- IF (channel = str_m_chan)
- AND ((tnc_cmd_data = 2) OR
- ((tnc_cmd_data = 3) AND (str_m_type >= t_to_h_mh_noi)) OR
- ((tnc_cmd_data = 4) AND (str_m_type < t_to_h_mh_noi)))
- THEN
- b := TRUE
- ELSE
- BEGIN;
- last_chain := look_chain;
- look_chain := str_m_next;
- END;
-
- (*-----------------------------------------------------------------*)
- (* Loop until we find something or run out of places to look *)
- (*-----------------------------------------------------------------*)
-
- UNTIL b OR (look_chain = NIL);
-
- (*-------------------------------------------------------------------*)
- (* If not lucky, leave. *)
- (*-------------------------------------------------------------------*)
-
- IF NOT b THEN
- BEGIN;
- tnc_data_queued := FALSE;
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Move data from FIFO queue to buffer *)
- (*-------------------------------------------------------------------*)
-
- WITH look_chain^ DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(look_chain);
- {$ENDIF}
-
- (*---------------------------------------------------------------*)
- (* Move data, type, and set null switch *)
- (*---------------------------------------------------------------*)
-
- MOVE(str_m_data, tnc_data, str_m_data.long_length + 3);
- tnc_type := str_m_type;
- tnc_null := tnc_data.long_length = 0;
-
- (*---------------------------------------------------------------*)
- (* Remove buffer from chain *)
- (*---------------------------------------------------------------*)
-
- IF look_chain = tnc_in_chn THEN
- BEGIN;
- tnc_in_chn := str_m_next;
- {$IFDEF DEBUG_SRTQ}
- last_chain := NIL;
- {$ENDIF}
- END
- ELSE
- last_chain^.str_m_next := str_m_next;
-
- (*---------------------------------------------------------------*)
- (* Size of buffer *)
- (*---------------------------------------------------------------*)
-
- i := str_m_data.long_length + 3 + 6;
-
- {$IFDEF DEBUG_SRTQ}
- trace_data('SRTQFR', i, look_chain, '');
- trace_data('SRTQFC', i, last_chain, '');
- trace_data('SRTQFN', i, str_m_next, '');
- {$ENDIF}
-
- END;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Dispose of buffer *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG}
- WRITELN('Freeing = ', i);
- {$ENDIF}
-
- FREEMEM(look_chain, i);
-
- {$IFDEF FREE_CHK}
- test_free_list;
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Signal that we did it *)
- (*-----------------------------------------------------------------------*)
-
- tnc_data_queued := TRUE;
-
- END;
-
- (*===========================================================================*)
- (* ADD_TNC_QUEUE *)
- (* Adds data to a thread's queue *)
- (*===========================================================================*)
-
- PROCEDURE add_tnc_queue(this_tcb : tcb_ptr;
- this_channel : BYTE);
- VAR
- i : WORD;
- last_chain : str_m_chain;
- look_chain : str_m_chain;
-
- BEGIN;
-
- WITH active_tcb^.tnc_data DO
-
- (*-----------------------------------------------------------------------*)
- (* Get a buffer space *)
- (*-----------------------------------------------------------------------*)
-
- i := long_length + 3 + 6;
-
- GETMEM(last_chain, i);
-
- (*-----------------------------------------------------------------------*)
- (* Build a buffer *)
- (*-----------------------------------------------------------------------*)
-
- WITH last_chain^ DO
- BEGIN;
- str_m_next := NIL;
- str_m_type := active_tcb^.tnc_type;
- str_m_chan := this_channel;
- MOVE(active_tcb^.tnc_data, str_m_data,
- active_tcb^.tnc_data.long_length + 3);
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Chain it on "FIFO" *)
- (*-----------------------------------------------------------------------*)
-
- WITH this_tcb^ DO
- BEGIN;
- look_chain := tnc_in_chn;
- IF look_chain = NIL THEN
- BEGIN;
-
- {$IFDEF DEBUG_SRTQ}
- trace_data('SRTQAH', i, last_chain, '');
- {$ENDIF}
-
- tnc_in_chn := last_chain
-
- END
- ELSE
- BEGIN;
-
- WHILE look_chain^.str_m_next <> NIL DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(look_chain);
- {$ENDIF}
-
- look_chain := look_chain^.str_m_next;
- END;
-
- {$IFDEF POINT_CHK}
- test_pointer(look_chain);
- {$ENDIF}
-
- look_chain^.str_m_next := last_chain;
-
- {$IFDEF DEBUG_SRTQ}
- trace_data('SRTQAE', i, last_chain, '');
- trace_data('SRTQAP', 0, look_chain, '');
- {$ENDIF}
-
- END;
-
- END;
-
- END;